﻿@model IEnumerable<FILSTARTUPS_CMS.Models.PostGrid>
@{
    ViewBag.Title = "Index";
}
@section Pagename
{
    <h1>
        Post <small>Articles for Filstartups</small></h1>
}
<!-- PROMPT CRUD OPERATION -->
 <script src="@Url.Content("~/Scripts/jquery.min.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/jquery-ui.min.js")" type="text/javascript"></script>
<script type="text/javascript">

    $(document).ready(function () {


        //        "{ 'query': '" + request.term + "' }",
        $('#query').autocomplete({
            source: function (request, response) {
                var parameters = ["query", request.term, "catid", $('#catidFK').val()];
                var paramList = '';
                if (parameters.length > 0) {
                    for (var i = 0; i < parameters.length; i += 2) {
                        if (paramList.length > 0) paramList += ',';
                        paramList += '"' + parameters[i] + '":"' + parameters[i + 1] + '"';
                    }
                }
                paramList = '{' + paramList + '}';
                $.ajax({
                    url: '/Post/GetPost',
                    type: "POST",
                    contentType: "application/json; charset=utf-8",
                    datatype: "json",
                    data: paramList ,
                    success: function (data) {
                        response($.map(data, function (item) {
                            return { label: item, value: item };
                        }))
                    }
                });
            },
            minLenght: 2
        });
    });   

</script>
@if (TempData["message"] != null)
{
    <div class="alert-message success  span12 left append-top" id="tempdata">
        <center>@TempData["message"]</center>
    </div>
}
<!-- END PROMPT CRUD OPERATION -->
<div class="row">
    <!-- FILTER DATA -->
    <div class="span4">
        <div class="span3">
            <h2>
                Create Post</h2>
            <div class="createclass">@Html.ActionLink("Create New Article", "Create", "Post")</div>
            <div class="createclass">@Html.ActionLink("Create New Event", "CreateEvent", "Post")</div>
        </div>
    </div>
    <!-- END FILTER -->
    <!-- START UPDATE DIV -->
    <div class="span10">
        @using (Ajax.BeginForm("SearchCategory", "Post", new AjaxOptions
    {
        HttpMethod = "GET",
        UpdateTargetId = "PostCategory",
        InsertionMode = InsertionMode.Replace

    }, new { @class = "form-stacked" }))
        {
            <fieldset>
                <legend>Filter Post</legend>
                @Html.DropDownList("catidFK", new SelectList(ViewData["category"] as System.Collections.IEnumerable,
                                                                 "catidPK", "categoryname"))
                <input type="text" id="query" name="query" />
                <input type="submit" value="Filter" />
            </fieldset>
        }
        <div id="PostCategory">
            @Html.Partial("_PostList")
        </div>
    </div>
    <!-- END UPDATE DIV --->
    <!-- END -->
</div>
